package com.ruoyi.mall.app.task;

import com.ruoyi.mall.app.service.DtsGoodsEsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 商品数据同步到 Elasticsearch 定时任务
 */
@Component
public class DtsGoodsEsSyncTask {

    @Autowired
    private DtsGoodsEsService dtsGoodsEsService;

    /**
     * 每天凌晨 2:00 执行一次
     */
    @Scheduled(cron = "0 0 2 * * ?")
    public void syncGoodsToElasticsearch() {
        System.out.println("【开始】同步所有商品数据到 Elasticsearch");
        dtsGoodsEsService.syncAllToElasticsearch();
        dtsGoodsEsService.selectCategoryGoodsEs();
        System.out.println("【完成】商品数据已成功同步到 Elasticsearch");
    }
}
